package com.chris.design.pattern.java8;

import com.alibaba.fastjson.JSON;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author Chris
 */
public class Demo {

    public static void main(String[] args) {
        Person[] ps = new Person[6];
        Person p = null;
        for (int i = 0; i < 6; i++) {
            p = new Person(i, "name-" + i, "nickname-" + i, i, null, null, null);
            ps[i] = p;
            if (i == 5) {
                ps[i] = new Person(i, "name-" + i, "nickname-" + i, i, "Chris", null, "Shang");
            }
        }
        Arrays.sort(ps, Comparator.comparing(Person::getName).thenComparing(Person::getNickName));
        System.out.println(JSON.toJSONString(ps, true));

        System.out.println("=======分割线===================");

        // 自然排序
        Arrays.sort(ps, Comparator.comparing(Person::getName, Comparator.nullsFirst(Comparator.naturalOrder())));
        // 自然排序的相反顺序
        Arrays.sort(ps, Comparator.comparing(Person::getName, Comparator.nullsFirst(Comparator.reverseOrder())));

        System.out.println(JSON.toJSONString(ps, true));
    }
}
